/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ugc.cnel.manabi.entidades;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 *
 * @author Admin
 */
@Entity
@Table(name = "servicio", catalog = "", schema = "public",uniqueConstraints={@UniqueConstraint(columnNames={"codigo_servicio","n_medidor"})})
@NamedQueries({
    @NamedQuery(name = "Servicio.findAll", query = "SELECT s FROM Servicio s"),
    @NamedQuery(name = "Servicio.findById", query = "SELECT s FROM Servicio s WHERE s.id = :id"),
    @NamedQuery(name = "Servicio.findByCodigoServicio", query = "SELECT s FROM Servicio s WHERE s.codigoServicio = :codigoServicio"),
    @NamedQuery(name = "Servicio.findByDetalleServicio", query = "SELECT s FROM Servicio s WHERE s.detalleServicio = :detalleServicio"),
    @NamedQuery(name = "Servicio.findByNMedidor", query = "SELECT s FROM Servicio s WHERE s.nMedidor = :nMedidor"),
    @NamedQuery(name = "Servicio.findByBorrado", query = "SELECT s FROM Servicio s WHERE s.borrado = :borrado")
})
public class Servicio implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "id", nullable = false)
    private Integer id;
    @Basic(optional = false)
    @Column(name = "codigo_servicio", nullable = false)
    private int codigoServicio;
    @Column(name = "detalle_servicio", length = 2147483647)
    private String detalleServicio;
    @Basic(optional = false)
    @Column(name = "n_medidor", nullable = false)
    private int nMedidor;
    @Basic(optional = false)
    @Column(name = "borrado", nullable = false)
    private boolean borrado;
    @JoinColumn(name = "id_cliente", referencedColumnName = "id", nullable = false)
    @ManyToOne(optional = false)
    private Cliente idCliente;
    @JoinColumn(name = "id_tipo_servicio", referencedColumnName = "id", nullable = false)
    @ManyToOne(optional = false)
    private TipoServicio idTipoServicio;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idServicio")
    @OrderBy(value="fechaInspeccion DESC")
    private Collection<Inspeccion> inspeccionCollection;

    public Servicio() {
    }

    public Servicio(Integer id) {
        this.id = id;
    }

    public Servicio(Integer id, int codigoServicio, int nMedidor) {
        this.id = id;
        this.codigoServicio = codigoServicio;
        this.nMedidor = nMedidor;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public int getCodigoServicio() {
        return codigoServicio;
    }

    public void setCodigoServicio(int codigoServicio) {
        this.codigoServicio = codigoServicio;
    }

    public String getDetalleServicio() {
        return detalleServicio;
    }

    public void setDetalleServicio(String detalleServicio) {
        this.detalleServicio = detalleServicio;
    }

    public int getNMedidor() {
        return nMedidor;
    }

    public void setNMedidor(int nMedidor) {
        this.nMedidor = nMedidor;
    }

    public boolean isBorrado() {
        return borrado;
    }

    public void setBorrado(boolean borrado) {
        this.borrado = borrado;
    }

    public Cliente getIdCliente() {
        return idCliente;
    }

    public void setIdCliente(Cliente idCliente) {
        this.idCliente = idCliente;
    }

    public TipoServicio getIdTipoServicio() {
        return idTipoServicio;
    }

    public void setIdTipoServicio(TipoServicio idTipoServicio) {
        this.idTipoServicio = idTipoServicio;
    }

    public Collection<Inspeccion> getInspeccionCollection() {
        return inspeccionCollection;
    }

    public void setInspeccionCollection(Collection<Inspeccion> inspeccionCollection) {
        this.inspeccionCollection = inspeccionCollection;
    }

    public int getnMedidor() {
        return nMedidor;
    }

    public void setnMedidor(int nMedidor) {
        this.nMedidor = nMedidor;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {

        if (!(object instanceof Servicio)) {
            return false;
        }
        Servicio other = (Servicio) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.ugc.cnel.manabi.entidades.Servicio[id=" + id + "]";
    }
}
